package com.pipe.connector.nettyhandler;

import com.pipe.exception.ColumnReaderException;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Kiven
 */
public class ExceptionHandler extends ChannelInboundHandlerAdapter {

    private static Logger LOG = LoggerFactory.getLogger(ExceptionHandler.class);

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        LOG.error("[EXCEPTION] - mysql connect error!", cause);
        if (! (cause instanceof ColumnReaderException)){
            ctx.channel().eventLoop().parent().shutdownGracefully();
        }
    }
}